import service from "../uitils/request"

export const deployStatusListApi = (appName, groupName) => {
    return service({
        url: "/deployStatus/list",
        method: 'GET',
        params: {
            appName: appName,
            groupName: groupName
        }
    })
}

export const lastApplyApi = (appName, envName) => {
    return service({
        url: "/deployApply/last",
        method: 'GET',
        params: {
            appName: appName,
            envName: envName,
        }
    })
}

export const getApplyByBuildIdApi = (buildId) => {
    return service({
        url: "/deployApply/byBuildId",
        method: 'GET',
        params: {
            buildId: buildId
        }
    })
}

export const submitApplyApi = (data) => {
    return service({
        url: "/deployApply/submit",
        method: 'POST',
        data
    })
}

export const deployByGroupApi = (deployGroupId) => {
    return service({
        url: "/deploy/deployByGroup",
        method: 'get',
        params: {
            deployGroupId: deployGroupId
        }
    })
}

export const deployByInstanceApi = (instanceId) => {
    return service({
        url: "/deploy/deployByInstance",
        method: 'get',
        params: {
            appInstanceId: instanceId
        }
    })
}

export const restartByInstanceApi = (instanceId) => {
    return service({
        url: "/deploy/restartByInstance",
        method: 'get',
        params: {
            appInstanceId: instanceId
        }
    })
}

export const saveDeployGroupPropApi = (deployGroupId, props) => {
    return service({
        url: "/manage/deployGroup/saveProp",
        method: 'POST',
        data: {
            id: deployGroupId,
            props: props
        }
    })
}
export const queryConfigFileListApi = (deployGroupId) => {
    return service({
        url: "/deployConfigFile/list",
        method: 'get',
        params: {
            deployGroupId: deployGroupId,
        }
    })
}

export const getConfigFileApi = (fileId) => {
    return service({
        url: `/deployConfigFile/${fileId}`,
        method: 'get'
    })
}

export const deleteConfigFileApi = (fileId) => {
    return service({
        url: `/deployConfigFile/${fileId}`,
        method: 'DELETE'
    })
}

export const saveDeployConfigFileApi = (data) => {
    return service({
        url: "/deployConfigFile/save",
        method: 'POST',
        data
    })
}

export const queryRecordPageApi = (params) => {
    return service({
        url: 'deploy/deployRecordPage',
        method: 'get',
        params
    })
}

export const getRecordDetailApi = (recordId) => {
    return service({
        url: 'deploy/getDeployRecord',
        method: 'get',
        params: {recordId: recordId}
    })
}

export const lastRecordByGroupApi = (deployGroupId) => {
    return service({
        url: 'deploy/lastRecordByGroup',
        method: 'get',
        params: {deployGroupId: deployGroupId}
    })
}


export const logSearchApi = (instanceId, date, beginTime, endTime, keyword) => {
    return service({
        url: "/logSearch",
        method: 'get',
        params: {
            instanceId: instanceId,
            date: date,
            beginTime: beginTime,
            endTime: endTime,
            keyword: keyword,
        }
    })
}


export const logSearchContentApi = (instanceId, fileName, beginNum, endNum) => {
    return service({
        url: "/logSearch/context",
        method: 'get',
        params: {
            instanceId: instanceId,
            fileName: fileName,
            beginNum: beginNum,
            endNum: endNum,
        }
    })
}

export const logFileListApi = (appInstanceId, dir) => {
    return service({
        url: `/sshFile/list/appInstanceLog`,
        method: 'GET',
        params: {
            appInstanceId: appInstanceId,
            dir: dir,
        }
    })
}

export const downloadLogFileApi = (appInstanceId, fileName) => {
    return service({
        url: `/sshFile/download/appInstanceLog`,
        method: 'GET',
        responseType: 'blob',
        timeout: 1000 * 60 * 10,
        params: {
            appInstanceId: appInstanceId,
            fileName: fileName
        }
    })
}
